package com.springmvc.demo.config;

import com.springmvc.demo.handlemapping.UserHandleMapping;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.*;

import javax.annotation.Resource;
import java.time.Duration;
import java.util.List;

@EnableWebMvc
@ComponentScan("com.springmvc.demo")
@Configuration
public class AppConfig implements WebMvcConfigurer {

	@Resource
	private UserHandleMapping userHandleMapping;
//	@Override
//	public void configureViewResolvers(ViewResolverRegistry registry) {
		//指定静态资源
//		registry.jsp("/WEB-INF/jsp/",".jsp");
//		registry.jsp("/static/jsp/",".jsp");
//	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/resources/**")
				.addResourceLocations("classpath:/static/**")
		.setCacheControl(CacheControl.maxAge(Duration.ofDays(365)));
	}

	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
		resolvers.add(0,userHandleMapping);
	}
}
